<template>
  <div class="main">
    <div class="weather container">
      <ul class="weather-list">
        <li class="weather-list-item">{{ weatherData.temperature }}</li>
        <li class="weather-list-item">{{ weatherData.city }}</li>
        <li class="weather-list-item">{{ weatherData.weather }}</li>
      </ul>
    </div>
    <div class="search container">
      <router-link to="" class="search-box">
        <i class="fl icon-search"></i>
        <input type="search" placeholder="请输入关键词搜索" class="search-input">
      </router-link>
    </div>

    <div class="swiper-container">
      <van-swipe type="card" width="100%" :loop="bannerSet.loop" :autoplay="bannerSet.autoplay"
                 :show-indicators="bannerSet.showIndicators" class="swiper">
        <van-swipe-item v-for="(item,index) in bannerList" :key="index" class="swiper-item" :default="item.num">
          <router-link to="">
            <img :src="item.imgUrl" alt="" class="swiper-img">
          </router-link>
        </van-swipe-item>
      </van-swipe>
    </div>

    <div class="tourism-container container">
      <ul class="tourism-list">
        <li v-for="(item,index) in tourismList" :key="index" class="tourism-list-item">
          <router-link :to="item.path" >
            <img :src="item.imgUrl" alt="" class="tourism-img">
          </router-link>
        </li>
      </ul>
    </div>

    <div class="food-container container">
      <div class="food-title text-center">食品推荐</div>
      <div class="food-swiper-container">
        <swiper class="swiper" :options="foodSwiperOption">
          <swiper-slide v-for="(item,index) in foodList" :key="index">
            <router-link to="">
              <img :src="item.imgUrl" alt="" class="swiper-img">
            </router-link>
          </swiper-slide>
        </swiper>
      </div>
    </div>

    <div class="partners-container container">
      <div class="partners-title text-center">合作伙伴</div>
      <div class="partners-main"><img v-for="(item,index) in partnersImage" :key="index" :src="item" alt=""></div>
    </div>

  </div>
</template>
<script>
import axios from 'axios';
import {Swiper, SwiperSlide} from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'

export default {

  data() {
    return {
      weatherData: {
        weather: "",
        temperature: "",
        city: ""
      },
      bannerList: [
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner1.png",
          path: "",
          num: 1,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner2.png",
          path: "",
          num: 2,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner3.png",
          path: "",
          num: 1,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner4.png",
          path: "",
          num: 2,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner5.png",
          path: "",
          num: 1,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner6.png",
          path: "",
          num: 2,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner7.png",
          path: "",
          num: 1,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner8.png",
          path: "",
          num: 2,
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner9.png",
          path: "",
          num: 1,
        },

        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/banner10.png",
          path: "",
          num: 2,
        },
      ],
      bannerSet: {
        loop: true,
        autoplay: 3000,
        showIndicators: false
      },
      tourismList: [
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/01.png",
          path: "/attractions/chaozhou-ancient-city",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/02.png",
          path: "/attractions/guangji-bridge",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/03.png",
          path: "/attractions/korean-temple",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/04.png",
          path: "/attractions/pavilions-street",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/05.png",
          path: "/attractions/kaiyuan-temple",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/06.png",
          path: "/attractions/longhu-ancient-village",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/07.png",
          path: "/attractions/xu-consort-mansion",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/tourism/08.png",
          path: "/attractions/qinglong-ancient-temple",
        },
      ],
      foodSwiperOption: {
        slidesPerView: 2,
        spaceBetween: 10,
        loop: true,
      },
      foodList: [
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/food/01.png",
          path: "",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/food/02.png",
          path: "",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/food/03.png",
          path: "",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/food/04.png",
          path: "",
        },
        {
          imgUrl: "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/food/05.png",
          path: "",
        },
      ],
      partnersImage:[
        "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/cooperative%20partner.png",
        "https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/Guidance%20unit.png"
      ],
    }
  },
  components: {
    Swiper,
    SwiperSlide
  },
  mounted() {
    this.getWeather();
  },
  methods: {
    async getWeather() {
      const response = await axios.get("https://api.seniverse.com/v3/weather/now.json?key=SnpvyMln-0jMQzhrR&location=chaozhou&language=zh-Hans");
      const data = response.data.results[0];
      let arr = data.location.path.split(",");
      this.weatherData.city = arr[3] + "省" + arr[2] + '市';
      this.weatherData.temperature = data.now.temperature + "℃";
      this.weatherData.weather = data.now.text;
    },
  }

}
</script>
<style lang="less" scoped>
.main {
  width: 100%;
  height: 100%;
  background-image: url("https://wlhp-cultural-tourism.oss-cn-beijing.aliyuncs.com/Index/background.png");
  background-color: var(--black-color-0);
  background-size: 100%;

  background-repeat: no-repeat;
}

.weather {
  padding-top: 40px;

  .weather-list {
    display: flex;
    align-items: end;

    .weather-list-item {
      color: var(--black-color-0);
      padding-right: 8pt;
      font-size: 10pt;

      &:first-child {
        font-size: 24pt;
      }

    }
  }
}

.search {
  padding-top: 10pt;

  .search-box {
    display: block;
    width: 100%;
    height: 24pt;
    background-color: var(--black-color-0);
    border-radius: 36pt;

    [class*='icon-search'] {
      display: block;
      height: 24pt;
      line-height: 24pt;
      width: 34pt;
      text-align: center;
      color: var(--black-color-25);
    }

    .search-input {
      display: block;
      width: calc(100% - 45pt);
      height: 24pt;
      border: none;
      background-color: transparent;
      font-size: 10pt;
    }
  }
}

.swiper-container {
  margin-top: 330px;
  padding-bottom: 10pt;

  .swiper {
    .swiper-item {
      padding: 10px 10px;

      .swiper-img {
        width: 100%;
        object-position: 50% 50%;
        object-fit: cover;
      }
    }
  }
}

.tourism-container {
  margin: 15px auto 0;

  .tourism-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;

    .tourism-list-item {
      .tourism-img {
        width: 100%;
      }
    }
  }

}

.food-container {

  .food-title {
    padding: 50px 0 10px;
    font-size: 18pt;
  }

  .food-swiper-container {
    .swiper-container {
      margin: 0;
      padding: 0;

      .swiper-img {
        width: 100%;
      }
    }
  }

}

.partners-container {
  .partners-title {
    padding: 20px 0 10px;
    font-size: 18pt;
  }
  .partners-main{
    width: 100%;
    padding-bottom: 30px;
    img{
      width: 100%;
      margin-bottom: 5px;
    }
  }
}
</style>